from flask import Flask, Blueprint, render_template, session, redirect, url_for, request, Response, jsonify
# 这里注意要导入models中的models，而不是extends中的models
from App.models import *

breakblue = Blueprint('breakblue', __name__)


@breakblue.route('/break/viewBreak')
def viewBreak():
    # 从数据库中查询break所有信息
    # 从数据中查询出来的结果
    resultList = Break.query.filter().all()
    # 将结果转化为字典
    # result_dict = [dict(model) for model in result]
    breakList = []

    if resultList:
        for resultItem in resultList:
            # 开始存数据
            breakItem = {
                "breakid": resultItem.breakid,
                "did": resultItem.did,
                "breaker": resultItem.breaker,
                "entertime": resultItem.entertime,
                "leavetime": resultItem.leavetime,
                "level": resultItem.level,
                # 0表示不是宿舍成员，1表示是宿舍成员，默认为1
                "isMember": '1'
            }
            breakList.append(breakItem)
            print(breakItem)

    return render_template('break-in-record.html', breakList=breakList)


# @breakblue.route('/')
# def


@breakblue.route('/break/viewInTime')
def view_intime():
    return render_template("intime-moni.html")
